package com.situ.skymallaiapi.api;

import com.situ.utils.JsonResult;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping(value = "/api/v1/ais",produces = MediaType.APPLICATION_JSON_VALUE)
public class ChatApi {
    private ChatClient chatClient;
    @Autowired
    public void setChatClient(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    /**
     * AI客服
     * @param question 问题
     */
    @RequestMapping("/chat")
    private Flux<ResponseEntity<JsonResult<?>>> chat(String question) {
        return chatClient
                .prompt()
                .system("你是一名商城客服，负责解答客户的问题，态度要好。")
                .user(question)
                .stream()
                .content()
                .map(content -> ResponseEntity.ok(JsonResult.success(content)));
    }
}
